/**
 * Copyright &copy; 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.zhixun.mobile.modules.edu.utils;

import java.util.List;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.UnavailableSecurityManagerException;
import org.apache.shiro.subject.Subject;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import com.boxin.framework.base.dao.DaoHelper;
import com.boxin.ims.modules.education.entity.Binding;
import com.boxin.ims.modules.education.entity.Student;
import com.boxin.ims.modules.education.service.BindingService;
import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.sys.dao.AreaDao;
import com.thinkgem.jeesite.modules.sys.dao.MenuDao;
import com.thinkgem.jeesite.modules.sys.dao.OfficeDao;
import com.thinkgem.jeesite.modules.sys.dao.UserDao;
import com.thinkgem.jeesite.modules.sys.entity.Area;
import com.thinkgem.jeesite.modules.sys.entity.Menu;
import com.thinkgem.jeesite.modules.sys.entity.Office;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.security.SystemRealm.Principal;

/**
 * 用户工具类
 * @author ThinkGem
 * @version 2013-4-21
 */
@Service
public class BindingUtils implements ApplicationContextAware {
	private static Map<String, Object> map = Maps.newHashMap();
	private static BindingService bindingService;
	
	
	
	public static List<Binding> getBindingList(Binding binding){
		@SuppressWarnings("unchecked")
		List<Binding> bindingList = (List<Binding>)getCache("bindingList");
			bindingList=bindingService.findBindingByMember(binding);
			putCache("bindingList", bindingList);
		return bindingList;
	}
	
	public static void setBinding(Binding binding){
		putCache("binding", binding);
	}
	
	public static Binding getBinding(){
		return (Binding)getCache("binding");
	}
	
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext){
		bindingService = (BindingService)applicationContext.getBean("bindingService");
	}
	
	
	
	// ============== User Cache ==============
	
	public static Object getCache(String key) {
		return getCache(key, null);
	}
	
	public static Object getCache(String key, Object defaultValue) {
		Object obj = getCacheMap().get(key);
		return obj==defaultValue?defaultValue:obj;
	}

	public static void putCache(String key, Object value) {
		getCacheMap().put(key, value);
	}

	public static void removeCache(String key) {
		getCacheMap().remove(key);
	}
	
	private static Map<String, Object> getCacheMap(){
		
		return map;
	}
}
